home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 October / macformat-005.iso / Shareware City / Developers / xlispmac / lisp / dragon.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1994-06-25  |  1.1 KB  |  40 lines  |  [TEXT/xlsp]

  1. ; dragon.lsp for MacXLisp 2.1g by Tom Almy and Brian Kendig
  2. ;
  3. ; An Nth-order dragon curve using turtle drawing routines.
  4. ; Originally from Byte (April 1986), converted to xlisp
  5. ; by Peter Ashwood-Smith, modified by Tom Almy and Brian Kendig.
  6. ;
  7. ; Note that you have to have turtle.lsp loaded for this to work.
  8. ; And you might want to press Command-Period to stop the program
  9. ; when it starts drawing beyond the window where you can't see it.
  10. ;
  11. ;              P.S - This dragon is nicknamed "spot".
  12.  
  13. #-:turtle (load "turtle")
  14.  
  15. (defvar *StepSize* 1)
  16.  
  17. (defun Dragon (sign level)
  18.   (if (zerop level) 
  19.     (TurtleForward *StepSize*)
  20.     (progn
  21.       (setq level (1- level))
  22.       (TurtleRight (* 45 sign))
  23.       (Dragon -1 level)
  24.       (TurtleLeft (* 90 sign))
  25.       (Dragon 1 level)
  26.       (TurtleRight (* 45 sign)))))
  27.  
  28. (defun DragonCurve (n m)
  29.   (setq *StepSize* m)  ; *StepSize* is global variable
  30.   (TurtleGraphicsUp)
  31.   (color 0 40000 0)
  32.   (TurtleCenter)
  33.   (TurtleGoto 50 50)
  34.   (TurtleRight 30)  ; angle the serpent a bit
  35.   (Dragon 1 n)
  36.   (gc))
  37.  
  38. (print "Try (DragonCurve 14 3)")
  39.  
  40.